<template>
	<view class="fboxCol Ycenter Xcenter" v-if="imgData">
		<image :class="className" :src="imgData.url" mode="widthFix" @tap="pageTo"></image>
	</view>
</template>

<script>
	import { bksFunctionInfo } from '@/api/bks.index.js'
	import { bannerStatistical } from '@/api/bks.login.js'
	import { getRequest, parseQueryStringt } from '@/static/js/common.js';
	export default {
		props: {
			className: {
				type: String,
				default: 'w690 radius8'
			},
			imgCode: {
				type: String,
				default: ''
			},
			type: {
				type: String,
				default: 'expert'
			}
		},
		data() {
			return {
				imgData: null
			}
		},
		mounted() {
			this.init()
		},
		methods: {
			init() {
				bksFunctionInfo({
					identify: this.imgCode
				}).then(res => {
					if (res.data) {
						if (res.data.list[0]) {
							this.imgData = res.data.list[0] || null
						} else {
							this.imgData = {
								url: res.data.functionUrl,
								jumpUrl: ''
							}
						}
					} else {
						this.imgData = null
					}
				})
			},
			// 跳转
			pageTo(e) {
				const {
					jumpUrl,
					id,
					type
				} = this.imgData
				console.log(this.imgData)
				if (jumpUrl.indexOf('tips:') != -1) {
					let title = jumpUrl.split(':')[1]
					wx.showToast({
						title,
						icon: 'none'
					})
				} else if (jumpUrl) {
					if (type == 1) {
						// #ifdef H5
							window.location.href = jumpUrl
						// #endif
						// #ifdef MP
							uni.navigateTo({
								url: '/web-view?url=' + encodeURIComponent(encodeURI(jumpUrl)),
								success(res) {
									// 打开成功的回调函数
									console.log('成功啦=====');
								},
								fail(res) {
									// 打开失败的回调函数
								}
							});
						// #endif
						
						const bw_bks_user = uni.getStorageSync('bw_bks_user') || ''
						const query = parseQueryStringt(jumpUrl)
						bannerStatistical({
							adId: id,
							linkId: query.id,
							memberId: bw_bks_user.memberId
						})
					} else {
						const newPath = jumpUrl.replace('/pages/', '/bks/')
						this.$pageTo(newPath)
					}
				} else {
					console.log('jumpUrl空不能跳转')
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
.w690{width: 690rpx;}
.radius8{border-radius: 8rpx;}
</style>